home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / Control Panel 0.9.4 / READ ME ;-) < prev    next >
Encoding:
Text File  |  1994-02-02  |  7.1 KB  |  76 lines  |  [TEXT/EDIT]

  1. READ ME file for the Sample Control Panel Project
  2. February 1994
  3.  
  4. First of all, I welcome ANY comments, suggestions, error reports, instructions, expletives or even compliments concerning this project.  Send e-mail to me at AOL KNEworley or mail to Ken Worley, P.O. Box 722, Cheyenne WY 82003.  Thanks.
  5.  
  6. WELCOME to the distorted little world of system level Macintosh programming (or Howdy if you're already here)!  Writing a control panel is fairly easy.  Getting it to do something useful and work along with an extension is something else altogether.  This project may not do anything REAL useful, but it goes a long ways towards that goal and does a good job of integrating an extension, a control panel, and a trap patch (code that modifies the behavior of a Toolbox routine).
  7.  
  8. Since I don't know your skill level but I'm no teacher, I'll assume you have an intermediate level of knowledge about this subject.  What I've learned about this stuff has come from numerous other examples and from many osmosis sessions with Inside Macintosh (I've got the majority of the New Inside Mac books).  To say the least, extracting just the information relevant to this subject from Inside Macintosh is a chore and I have yet to do it.  Some of what I know comes from there, and some (as I said) comes from what others have shared.  I'll share what I know, but don't expect it to be GOSPEL.  I had a hard time finding a lot of the information I needed in one place, so I thought I'd share much of what I've learned so far with you all in one project.
  9.  
  10. WHAT I USED TO WRITE THIS PROJECT
  11.  
  12. I have a Macintosh Performa 405 (LCII).  I used THINK C 6.0.1 to write this project (though it should work in earlier versions as well).  I generally don't pay as much attention to making things as System 6 compatible as I should because I use only System 7 (even on my puny old Mac Classic).  You might think that's selfish, but at least I admit I have a problem :-).
  13.  
  14. WHAT THIS PROJECT DOES
  15.  
  16. This project is a simple extension, control panel combination that installs and controls a trap patch.  In its unmodified form, it patches the MenuSelect trap so that if the "About This Macintosh…" menu item is picked, a dialog comes up that the user has to dismiss before the about box appears.
  17.  
  18. HOW THE PROJECT IS ORGANIZED
  19.  
  20. There are actually three separate projects involved here:
  21.             Control Panel.π - the control panel code (includes MyControlPanel.c)
  22.             Extension.π - the extension code (includes MyExtension.c)
  23.             Patch.π - the trap patch code (includes MyPatch.c)
  24.  
  25. Other files included are:
  26.             Notifier.c and Notifier.h - code included by MyPatch.c
  27.             Control Panel.π.rsrc - resources for the finished control panel
  28.             SharedData.h - info included by MyControlPanel.c, MyExtension.c, & MyPatch.c
  29.             ShowIconFamily.c - code included by MyExtension.c
  30.             SampleControlPanel - a finished control panel built using this project
  31.                     Drop it into your System folder and restart to see it work.
  32.  
  33. If you're building the projects from the source code only, follow these vague steps:
  34.             PUT ALL THIS STUFF IN THE SAME FOLDER
  35.             1.  Create a new project of type Code Resource.
  36.                         Name the project Control Panel.π
  37.                         Make sure the system heap and locked attributes are set for the project
  38.                         Include "MacTraps" and "MyControlPanel.c" in the project
  39.                         Make sure you have the Control Panel.π.rsrc file
  40.                         Make sure you have the SharedData.h file
  41.                         When you 'build' this code resource, use the name SampleControlPanel
  42.                         When you 'build' this code resource, do NOT check the merge box
  43.             2.  Create a new project of type Code Resource.
  44.                         Name the project Extension.π
  45.                         Include "MacTraps" and "MyExtension.c" in the project
  46.                         Make sure you have the SharedData.h file
  47.                         Make sure you have the ShowIconFamily.c file
  48.                         When you 'build' this code resource, use the name SampleControlPanel
  49.                         When you 'build' this code resource, CHECK the merge box
  50.                                 (this will add this code to SampleControlPanel, not create a new file)
  51.             3.  Create a new project of type Code Resource.
  52.                         Name the project Patch.π
  53.                         Include "ANSI-A4," "MacTraps" and "MyPatch.c" in the project
  54.                         Make sure you have the "Notifier.c" and "Notifier.h" files
  55.                         Make sure you have the SharedData.h file
  56.                         When you 'build' this code resource, use the name SampleControlPanel
  57.                         When you 'build' this code resource, CHECK the merge box
  58.                                 (this will add this code to SampleControlPanel, not create a new file)
  59.  
  60. HOW THE PROJECT WORKS
  61.  
  62. This is a general, brief discussion.  Specifics are documented in the code itself.
  63.  
  64. The extension allocates a memory structure that contains all the global data needed by the control panel and trap patch.  It stores the address of this memory structure in a resource for later access by the control panel.  It checks the 'pref' resource for settings retained from before the last startup, then it loads the patch code into memory, modifies it so that it knows how to access the shared memory, and installs it as a patch to a particular trap (if the control panel was set to "on").  It also displays its icon during startup.
  65.  
  66. The control panel gains access to the shared memory structure by reading the address from a resource written by the extension at startup time.  The control panel turns the patch "on" or "off."  If the control panel is set to "off" when the computer starts up, the 'pref' resource will indicate that the extension should not install the trap patch.  In that case, the control panel can then be turned "on," but the patch won't be installed until a restart.  If the control panel is set to "on" when the computer starts up, the 'pref' resource will indicate that the extension should install the trap patch.  In that case, the control panel can then be turned "off" which disables the patch, but can then be turned back on to reenable the patch.  The patch knows whether the control panel is "on" or "off" through the shared memory.  The control panel not only records its settings in the shared memory, but also in the 'pref' resource so that settings are retained even through a restart.
  67.  
  68. The patch intercepts a call to whichever trap it was installed for.  It can return a value of its own choosing without calling the original trap, call the original trap without modification (which is what it does when the control panel is "off"), or call the original trap and modify its return value.  The patch checks control panel settings through the memory it shares with the control panel.
  69.  
  70. In this particular case, I've patched the MenuSelect trap.  The patch calls the original trap and examines the return value.  If the user selected the "About This Macintosh…" menu item, the patch puts up a Notification dialog, then allows the about box to be shown (by passing the original trap's return value back through).
  71.  
  72. COMMENTS
  73.  
  74. The code is heavily documented and designed to be easily changed for different purposes.  There are parts that may be difficult to understand or are sparsely documented.  These are parts which would likely remain the same in any control panel project.  Again, if you have any questions or complaints, please send me a message.  I don't check my mail REAL often, so be patient and GOOD LUCK!
  75.  
  76.